package edu.ucsd.db.bassarisk.algebra.logical;

import edu.ucsd.db.bassarisk.algebra.logical.visitor.LogicalOperatorVisitor;

public class WithinContext extends LogicalOperator {
  private final LogicalOperator context;
  private final LogicalOperator subplan;

  public WithinContext(LogicalOperator context, LogicalOperator subplan) {
    this.context = context;
    this.subplan = subplan;
  }

  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("WithinContext {\n");
    sb.append(context.toString()).append("\n");
    sb.append("} do {\n");
    sb.append(subplan.toString()).append("\n");
    sb.append("}\n");
    return sb.toString();
  }

  @Override
  public <R, A> R accept(LogicalOperatorVisitor<R, A> visitor, A arg) {
    return visitor.visitWithinContext(this, arg);
  }

  public LogicalOperator filterPlan() {
    return context;
  }

  public LogicalOperator subPlan() {
    return subplan;
  }
}
